home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Tools⁄Additions / MacUserProj / MacUser Projects / June / 2GenApp Src / Shell.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-25  |  8.2 KB  |  349 lines  |  [TEXT/KAHL]

  1. /* *****************************************************************************
  2.     FILE:             Shell.c
  3.     
  4.     DESCRIPTION:     Main event loop and event handling utilities
  5.  
  6.     AUTHOR:            Kurt W.G. Matthies
  7.         
  8.     Copyright © 1990 by Code of the West, Inc. All Rights Reserved.
  9.     
  10.     Revision History:
  11.     ==========================================================
  12.     4.24.90 -    June 1990 MacUser Release
  13.     3.30.90    -    May 1990 MacUser Release
  14.     ==========================================================
  15.  
  16.    ***************************************************************************** */
  17. #define _Main_Module_
  18.  
  19. #include "AppGlobals.h"
  20.  
  21. #include "Version.h"
  22.  
  23. #ifdef V2
  24. #include <ControlMgr.h>
  25. #include <DialogMgr.h>
  26. #include <EventMgr.h>
  27. #endif
  28.  
  29. #include "AppInitPr.h"
  30. #include "DisplayPr.h"
  31. #include "DocUtilPr.h"
  32. #include "MenuUtilPr.h"
  33. #include "MiscUtilPr.h"
  34. #include "WindowUtilPr.h"
  35.  
  36. #include "ShellPr.h"
  37.     
  38.     
  39. /* --------------------  Local Prototypes --------------------------------- */
  40.                         main                    ( void );
  41. void                    doKeyDown                 ( EventRecord *e );
  42. void                    doMouseDown             ( EventRecord *e );
  43. void                    doActivateEvent            ( EventRecord *e );
  44. void                    doUpdateEvent            ( EventRecord *e );
  45. void                    doSuspendResume            ( EventRecord *e );
  46. void                    doInContent             ( WindowPtr, EventRecord *e );
  47. /* -------------------------------------------------------------------------
  48.     main -    program entry point
  49. ---------------------------------------------------------------------------- */
  50. main ()
  51. {
  52.     EventRecord      event;
  53.     short             dItem;
  54.     DialogPtr        dialogPtr;
  55.     Boolean            result;
  56.     long            waitTicks;
  57.  
  58.     initApplication ();
  59.     
  60.     openAppDocs ();
  61.  
  62.     FlushEvents (everyEvent, 0);    /* dump all pending events */
  63.     
  64.     waitTicks = 20;        /* the Multifinder share time value */
  65.     
  66.     for (;;)    /* main event */
  67.     {    
  68.         if (gHasWNE)
  69.             result = WaitNextEvent (everyEvent, &event, waitTicks, 0L);
  70.         else
  71.         {
  72.             SystemTask ();
  73.             result = GetNextEvent (everyEvent, &event);
  74.         }
  75.         
  76.         if (result)
  77.         {
  78.             fixMenus ();            /* hilite/unhilite appropriate menu items */
  79.  
  80.             switch (event.what) 
  81.             {
  82.                 case mouseDown:    
  83.                     doMouseDown (&event);
  84.                     break;
  85.             
  86.                 case keyDown:
  87.                     doKeyDown (&event);
  88.                     break;
  89.             
  90.                 case activateEvt:    
  91.                     doActivateEvent (&event);
  92.                     break;
  93.     
  94.                 case updateEvt:
  95.                     doUpdateEvent (&event);
  96.                     break;
  97.  
  98.                 case app4Evt:        /* multifinder suspend/resume event */
  99.                     doSuspendResume (&event);
  100.                     break;
  101.  
  102.                 default:
  103.                     break;
  104.                     
  105.             }
  106.         }
  107.     }
  108. } /* main event loop */
  109.  
  110. /*--------------------------------------------------------------------------
  111.     doKeyDown - react to a key down event
  112.     3.30.90kwgm
  113. ---------------------------------------------------------------------------*/
  114. static void 
  115. doKeyDown (e)
  116.     EventRecord     *e;
  117. {
  118.     char             c;
  119.     
  120.     c = e->message & charCodeMask;        /* get character from event record */
  121.     
  122.     if (e->modifiers & cmdKey)
  123.     {
  124.         doMenu (MenuKey (c));        /* do menu commands */
  125.         HiliteMenu (0);
  126.     }
  127. }
  128.  
  129. /*------------------------------------------------------------------------------
  130.     doMouseDown () -  react to a mouse down event
  131.     3.30.90kwgm
  132.     4.24.90kwgm -    modified for multiple window support
  133. --------------------------------------------------------------------------------*/
  134. static void 
  135. doMouseDown (e)
  136.     EventRecord     *e;
  137. {
  138.     WindowPtr         theWindow;
  139.     short              where;
  140.     long              newSize;
  141.     WStateData        **wDataHdl;
  142.     Rect            userState, stdState, portRect;
  143.  
  144.     where = FindWindow (e->where, &theWindow);
  145.     
  146.     switch (where)             /* where did the event occur ?? */
  147.     {
  148.         case inDesk :
  149.             break;
  150.         
  151.         case inMenuBar :
  152.             doMenu (MenuSelect (e->where));
  153.             break;
  154.         
  155.         case inSysWindow :
  156.             SystemClick (e, theWindow);
  157.             break;
  158.     
  159.         case inContent :
  160.             if (theWindow != FrontWindow() || !((WindowPeek)theWindow)->hilited)
  161.                 SelectWindow (theWindow);
  162.             else
  163.                 doInContent (theWindow, e);
  164.             break;
  165.  
  166. /* ### kwgm 4.24.90 - new stuff supports window controls */
  167.         case inDrag :                    /* title region */
  168.             if (!getDblClick(e))
  169.             {
  170.                 SelectWindow (theWindow);
  171.                 DragWindow (theWindow, e->where, &gGrayRgnRect);
  172.             }
  173.             else
  174.                 clickZoomWindow (theWindow);
  175.             break;
  176.     
  177.         case inGrow :
  178.             doGrowWindow (theWindow, e->where);
  179.             break;
  180.             
  181.         case inZoomIn:
  182.         case inZoomOut:
  183.             if (TrackBox (theWindow, e->where, where))
  184.                 doZoomBox (theWindow, where);
  185.             break;
  186. /* ### kwgm 4.24.90 */
  187.     
  188.         case inGoAway :
  189.             if (TrackGoAway (theWindow, e->where))
  190.             {
  191.                 if (e->modifiers & optionKey)
  192.                     closeAllDocs ();
  193.                 else
  194.                     doCloseDoc (theWindow);
  195.             }
  196.             break;
  197.     }
  198. } /* doMouseDown */
  199.  
  200. /*-----------------------------------------------------------------------------
  201.     doActivateEvent -    react to an activate event
  202.     3.30.90kwgm
  203.     4.24.90kwgm -    modified for multiple window support
  204. ------------------------------------------------------------------------------*/
  205. static void 
  206. doActivateEvent (e)
  207.     EventRecord     *e;
  208. {
  209.     WindowPtr         theWindow;          /* the active window */
  210.     ControlHandle    controlList;
  211.     Rect            scrollbarRect;
  212.  
  213.     theWindow = (WindowPtr) e->message;
  214.     SetPort (theWindow);
  215.  
  216.     HidePen();
  217.  
  218.     /* activate or deactivate all window controls */
  219.     controlList =  ((WindowPeek)theWindow)->controlList;
  220.     if (e->modifiers & activeFlag)
  221.     {
  222.         while (controlList)
  223.         {
  224.             ShowControl (controlList);
  225.             controlList = (*controlList)->nextControl;
  226.         }
  227.     }
  228.     else
  229.     {
  230.         while (controlList)
  231.         {
  232.             HideControl (controlList);
  233.             controlList = (*controlList)->nextControl;
  234.         }
  235.     }
  236.     
  237.     ShowPen();
  238.     
  239. /* ### kwgm 4.24.90 - addition to May 1990 version */
  240.     /* since HidePen was in effect during the
  241.         activation/deactivation of controls,
  242.         put the scroll bars, grow Icon into the refresh area 
  243.         so that they are drawn in the subsequent update event
  244.     */
  245.     invalScrollBars (theWindow, false);
  246. /* ### kwgm 4.24.90  */
  247.  
  248. } /* doActivateEvent */
  249.  
  250. /* ----------------------------------------------------------------------------
  251.     doUpdateEvent - react to the update event
  252.     3.30.90kwgm
  253.     4.24.90kwgm -    modified for multiple window support
  254. -------------------------------------------------------------------------------*/
  255. static void 
  256. doUpdateEvent (e)
  257.     EventRecord        *e;
  258. {
  259.     WindowPtr        theWindow;
  260.     GrafPtr            savePort;
  261.     
  262.     theWindow = (WindowPtr) e->message;
  263.  
  264.     if (((WindowPeek) theWindow)->windowKind  >= 1)        /* is my window?  */
  265.     {
  266.         GetPort (&savePort);
  267.         SetPort (theWindow);
  268.         BeginUpdate (theWindow);
  269.         
  270.         EraseRgn ((WindowPeek)theWindow->visRgn);
  271.  
  272. /* ### kwgm 4.24.90 - addition to May 1990 version */
  273.         drawScrollBars (theWindow, true);                
  274. /* ### kwgm 4.24.90  */
  275.         drawDocContents (theWindow);
  276.         
  277.         EndUpdate (theWindow);
  278.         SetPort (savePort);
  279.     }
  280.     
  281. } /* doUpdateEvent */
  282.  
  283. /* ------------------------------------------------------------------------------
  284.     doInContent -    called from doMouseDown, respond to mouse down in window
  285.     3.30.90kwgm 
  286. --------------------------------------------------------------------------------- */
  287. static void 
  288. doInContent ( theWindow, eventPtr)
  289.     WindowPtr                theWindow;
  290.     EventRecord                *eventPtr;
  291. {
  292.     short                    part;
  293.     ControlHandle            theControl;
  294.     Point                    where;
  295.     
  296.     where = eventPtr->where;
  297.     
  298.     GlobalToLocal (&where);
  299.         
  300.     /* nothing to do here this month */
  301.  
  302. }    /* doInContent */
  303.  
  304. /* -----------------------------------------------------------------------------------
  305.     doSuspendResume -    do necessary things on multifinder switch
  306.     3.30.90kwgm
  307. -------------------------------------------------------------------------------------- */
  308. static void 
  309. doSuspendResume (e)
  310.     EventRecord        *e;
  311. {
  312.     Boolean            activate;
  313.     WindowPtr        topWindow;
  314.     
  315.     /* Suspend == false, Resume == true */
  316.     activate = (e->message & 1) ? true : false;
  317.     
  318.     /* if active window, activate/deactivate */
  319.     topWindow = FrontWindow ();
  320.     
  321.     if ((((WindowPeek) topWindow)->windowKind == userKind)) 
  322.     {
  323.         if (activate)
  324.         {
  325.             SelectWindow (topWindow);
  326.             HiliteWindow (topWindow, true);
  327.         }
  328.         else
  329.             HiliteWindow (topWindow, false);
  330.     }
  331.  
  332. } /* doSuspendResume */
  333.  
  334. /*------------------------------------------------------------------------------
  335.     cleanExit -     do the assorted things which must be done on exit
  336.     3.30.90kwgm
  337.     4.24.90kwgm -    modified for multiple window support
  338. -------------------------------------------------------------------------------- */
  339. void 
  340. cleanExit (normal)
  341.     Boolean        normal;
  342. {
  343.     if (closeAllDocs ())     /* old stuff is removed */
  344.         ExitToShell ();
  345. }
  346.  
  347. /* ===============================  EOF  =======================================
  348.     Copyright © 1990 by Code of the West, Inc. All Rights Reserved.
  349. ================================================================================ */